package com.atqar.base;
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockDemo {
    public synchronized void a(){
        this.b();
        System.out.println("a");
    }

    public synchronized void b(){
        System.out.println("b");
    }




    private final ReentrantLock lock = new ReentrantLock();

    public void c()
    {
        lock.lock();
        try
        {
            System.out.println("c");
            d();
        }finally {
            lock.unlock();
        }
    }

    public void d()
    {
        lock.lock();
        try
        {
            System.out.println("d");
        }finally {
            lock.unlock();
        }
    }




    public static void main(String[] args) {
        ReentrantLockDemo reentrantLockDemo= new ReentrantLockDemo();
  /*      reentrantLockDemo.a();
        reentrantLockDemo.b();
        reentrantLockDemo.c();*/
        reentrantLockDemo.d();

    }

    /*

    synchronized和lock都是可重入锁,就是递归锁,外层方法获取锁后内层方法会自动获取锁

    */
}

